package com.servertrack

import grails.test.mixin.TestFor
import spock.lang.Specification

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Company)
class CompanySpec extends Specification {

	/*Company company
    void setup() {
		mockForConstraintsTests(Company)
		company = new Company(title: 'duinc', email: 'duinc@gmail.com', startDate: new Date("2001/1/18"))
		
    }

    void testConstraintsTitleUnique() {
		def test = new Company(title: 'duinc', email: 'some@gmail.com', startDate: new Date("2010/5/24"))
		mockForConstraintsTests(Company, [test])

		assertFalse company.validate()
		assertEquals 'unique', company.errors['title']

		company = new Company(title: 'some', email: 'some@gmail.com', startDate: new Date("2010/5/24"))
		assertTrue company.validate()
    }

    void testConstraintsTitleBlank() {
		company = new Company(title: '', email: 'some@gmail.com', startDate: new Date("2010/5/24"))
		assertFalse company.validate()
		assertEquals 'blank', company.errors['title']

		company = new Company(title: 'notempty', email: 'some@gmail.com', startDate: new Date("2010/5/24"))
		assertTrue company.validate()
    }
	
	void testConstraintsTitleSize() {
		company = new Company(title: 'd', email: 'some@gmail.com', startDate: new Date("2010/5/24"))
		assertFalse company.validate()
		assertEquals 'size', company.errors['title']

		company = new Company(title: '123456789012345678901234567890123456789012345678901', email: 'some@gmail.com', startDate: new Date("2010/5/24"))
		assertFalse company.validate()
		assertEquals 'size', company.errors['title']

		company = new Company(title: 'normalsize', email: 'some@gmail.com', startDate: new Date("2010/5/24"))
		assertTrue company.validate()
	}
	
	void testConstraintsEmailEmail() {
		company.email = 'somesting'
		assertFalse company.validate()
		assertEquals 'email', company.errors['email']

		company.email = 'valid@email.ru'
		assertTrue company.validate()
	}
	
	
	void testConstraintsEmailNullable() {
		company.email = ''
		assertTrue company.validate()
		assertNull company.errors['email']
	}
	
	void testConstraintsStartDateNullable() {
		company.dateCreated = null
		assertTrue company.validate()
		assertNull company.errors['startDate']
	}*/
	
}
